# Some variables are followed by these abbreviations
# fct = Factor, ordered, seven levels
# cat = Factor, unordered, three levels
# bin = Factor, dummy
# num = Numeric, dummy

# Confidence in Attribution ----------------------------------------------------
df$confidence_ord <- convert_confidence(df$confidence, to = "ordered")
df$confidence_cat <- convert_confidence(df$confidence, to = "categorical")
df$confidence_bin <- convert_confidence(df$confidence, to = "dummy")

# Support for Retribution ------------------------------------------------------
df$do_nothing <- factor(df$do_nothing, levels = c(0, 1), 
                        labels = c("Do not support", "Support"))

df$do_condemn <- factor(df$do_condemn, levels = c(0, 1), 
                        labels = c("Do not support", "Support"))

df$do_sanctions <- factor(df$do_sanctions, levels = c(0, 1), 
                          labels = c("Do not support", "Support"))

df$do_cyberespionage <- factor(df$do_cyberespionage, levels = c(0, 1), 
                               labels = c("Do not support", "Support"))

df$do_cyberattack <- factor(df$do_cyberattack, levels = c(0, 1), 
                            labels = c("Do not support", "Support"))

df$do_airstrikes <- factor(df$do_airstrikes, levels = c(0, 1), 
                           labels = c("Do not support", "Support"))

df$do_rank <- dplyr::case_when(df$do_cyberattack == "Support" ~ 4,
                               df$do_cyberespionage == "Support" ~ 3,
                               df$do_sanctions == "Support" ~ 2,
                               df$do_condemn == "Support" ~ 1,
                               df$do_nothing == "Support" ~ 0,
                               .default = NA)

df$support <- factor(df$do_rank,
                     levels = c(0, 1, 2, 3, 4, NA), 
                     labels = c("Nothing", 
                                "Condemn", 
                                "Sanctions", 
                                "Cyberespionage", 
                                "Cyberattack"), 
                     ordered = TRUE)

df$support_ord <- ordered(df$support)

df$support_cat <- ifelse(df$do_rank < 3, 0, ifelse(df$do_rank == 3, 1, 2)) |>
  factor(levels = c(0, 1, 2), labels = c("De-escalation", "Proportional", "Escalation")) |>
  stats::relevel(ref = "De-escalation")

df$support_bin <- ifelse(df$do_rank < 3, 0, 1) |>
  factor(levels = c(0, 1), labels = c("De-escalation", "Retaliation")) |>
  stats::relevel(ref = "De-escalation")

# Treatment Variables ----------------------------------------------------------
df$disavowal <- factor(df$disavowal, levels = c(0, 1, 2), 
                       labels = c("None", "Evidence", "Hypocrisy"))

df$endorsement <- factor(df$endorsement, levels = c(0, 1), 
                         labels = c("Not Endorsed", "Endorsed"))

df$interaction <- interaction(df$disavowal, df$endorsement)

treatments <- c("disavowal", "endorsement")
interactions <- "endorsement:disavowal"

# Pre-existing images ----------------------------------------------------------
df$china <- rate_feelings(df$rate_china, type = "all")
df$china_imputed <- rate_feelings(df$rate_china, type = "imputed")

df$eu <- rate_feelings(df$rate_eu, type = "all")
df$eu_imputed <- rate_feelings(df$rate_eu, type = "imputed")

countries <- c("china", "eu")
countries_imputed <- c("china_imputed", "eu_imputed")